package com.lbw.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.lbw.entity.ChapterEntity;
import com.lbw.entity.SubjectEntity;
import com.lbw.result.Result;
import com.lbw.result.ResultFactory;
import com.lbw.service.ChapterEntityService;
import com.lbw.service.SubjectEntityService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  章节控制器  前端控制器
 * </p>
 *
 * @author lbw
 * @since 2020-09-26
 */
@RestController
@RequestMapping("/chapterEntity")
@Api(tags = "章节")
public class ChapterEntityController {

    @Autowired
    private ChapterEntityService chapterEntityService;
    @Autowired
    private SubjectEntityService subjectEntityService;

    /**
     * 通过科目查询对应的章节信息
     * @return
     */
    @GetMapping("selectChapterBySubject")
    @ApiOperation("通过科目查询对应的章节信息")
    public Result selectChapterBySubject(@ApiParam("科目类型") @RequestParam(value = "type", required = true) Integer type) {

        LambdaQueryWrapper<ChapterEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ChapterEntity::getType,type)
        .orderByAsc(ChapterEntity::getChapterNum);
        List<ChapterEntity> chapterList = chapterEntityService.list(lambdaQueryWrapper);
        if (chapterList != null && !chapterList.isEmpty()) {
            return ResultFactory.success(chapterList);
        }
        return ResultFactory.fail("暂无章节！");
    }


}

